{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "faf0f0e8-8b07-48d8-81aa-4ea71923a50f",
   "metadata": {},
   "source": [
    "# Lollipop Plot\n",
    "\n",
    "Lollipop plots can replace traditional bar plots, for example to reduce clutter when bars would look too \"heavy\" or overwhelming. hvPlot does not provide a built-in function to build such plot, instead, this example overlays a `hvplot.scatter` plot with (for the dot at the end) with vertical lines created with the `holoviews.Segments` element.\n",
    "\n",
    ":::{note}\n",
    "This type of plot can also be called *stem* plot, which is how [Matplotlib](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.stem.html) calls it. *Stem plot* is a somewhat ambiguous name that can be confused with [*stem-and-leaf plots*](https://en.wikipedia.org/wiki/Stem-and-leaf_display).\n",
    ":::"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13a60429-db54-44f1-b42c-bad4df87986b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import holoviews as hv\n",
    "import hvplot.pandas  # noqa\n",
    "\n",
    "df = pd.DataFrame({'type': list('ABCDEF'), 'value': [10, 50, 30, 35, 60, 20]})\n",
    "\n",
    "# Create line segments for each stem\n",
    "segments = hv.Segments(\n",
    "    [(xv, 0, xv, yv) for xv, yv in zip(df['type'], df['value'])]\n",
    ").opts(line_width=4, color='lightgrey')\n",
    "# Markers at the top\n",
    "markers = df.hvplot.scatter(x='type', y='value', size=200)\n",
    "\n",
    "(segments * markers).opts(\n",
    "    height=300,\n",
    "    width=600,\n",
    "    ylim=(0, None),\n",
    "    xlabel='Type',\n",
    "    ylabel='Value',\n",
    "    title='Lollipop Plot'\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f436ed72-9ba8-49de-a191-27ce6c8426c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import holoviews as hv\n",
    "import hvplot.pandas  # noqa\n",
    "\n",
    "hv.extension('matplotlib')\n",
    "\n",
    "df = pd.DataFrame({'type': list(range(6)), 'value': [10, 50, 30, 35, 60, 20]})\n",
    "\n",
    "# Create line segments for each stem\n",
    "segments = hv.Segments(\n",
    "    [(xv, 0, xv, yv) for xv, yv in zip(df['type'], df['value'])]\n",
    ").opts(linewidth=4, color='lightgrey')\n",
    "# Markers at the top\n",
    "markers = df.hvplot.scatter(x='type', y='value').opts(s=250)\n",
    "\n",
    "(segments * markers).opts(\n",
    "    ylim=(0, None),\n",
    "    xlabel='Type',\n",
    "    ylabel='Value',\n",
    "    title='Lollipop Plot'\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5a0d1208-d760-4ac7-8fcc-899b3eeaf80b",
   "metadata": {},
   "source": [
    ":::{seealso}\n",
    "- [Scatter Plots reference documentation](../../ref/api/manual/hvplot.hvPlot.scatter.ipynb).\n",
    "- [HoloViews Segments Element](https://holoviews.org/reference/elements/bokeh/Segments.html)\n",
    "- [HoloViews Composing Elements guide](https://holoviews.org/user_guide/Composing_Elements.html)\n",
    ":::"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
